package com.cl.edu.service.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cl.edu.dao.AdminDAO;
import com.cl.edu.entity.Admin;

/**
 * 管理员信息相关操作
 * 
 * @author Administrator
 * 
 */
@Service
@Transactional
public class AdminManager {
	@Autowired
	private AdminDAO adminDAO;

 
	public boolean hasUsername(Admin admin) {
		List<Admin> list = adminDAO.findBy("username", admin.getUsername());
		return list.size() > 0;
	}

	public Admin isExist(Admin admin) {
		StringBuffer hql = new StringBuffer("from Admin model");
		hql.append(" where 1=1 ");
		hql.append(" and model.username = '").append(admin.getUsername())
				.append("' and model.password = '").append(admin.getPassword())
				.append("'");
		List<Admin> list = adminDAO.find(hql.toString());
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}
	
	/**
	 * 由id获取管理员信息 
	 * @param id
	 * @return
	 */
	public Admin getAdmin(Integer id){
		return adminDAO.get(id);
	}
	
	/**
	 * 更新管理员信息
	 * @param entity
	 */
	public void updateAdmin(Admin entity) {
		adminDAO.saveOrUpdate(entity);
	}
}
